import useQuery from '@/api/query'
import xuanRanFenLeiString from '@/utils/xuanRanFenLeiString'

  export const useFenLeiString = async () => {
    // console.log('准备发送分类请求接口')
    const res = await useQuery.get('https://big-event-vue-api-t.itheima.net/my/cate/list')
    // console.log('分类请求回来了,数据是',res)
    return res.data.data
  }

  // 添加
  export const useAddFenLeiString = async (cate_name,cate_alias) => {
    // console.log('准备发送添加分类请求接口')
    await useQuery.post('https://big-event-vue-api-t.itheima.net/my/cate/add',{
      cate_name,
      cate_alias,
    })
    
    // console.log('添加分类请求成功了')
    return await xuanRanFenLeiString()
  }

  // 刘改
  export const useUpdateFenLeiString = async (id,cate_name,cate_alias) => {
    // console.log('准备发送修改分类请求接口')
    await useQuery.put('https://big-event-vue-api-t.itheima.net/my/cate/info',{
      id,
      cate_name,
      cate_alias
    })
    
    // console.log('修改分类请求回来了,数据是',res)
    return await xuanRanFenLeiString()
  }

  // 删除
  export const useDelFenLeiString = async (id) => {
    console.log('准备发送删除分类请求接口')
    await useQuery.delete(`https://big-event-vue-api-t.itheima.net/my/cate/del`,{
      params: {
        id
      }
    })
    // console.log('删除分类请求回来了,数据是',res)
    return await xuanRanFenLeiString()
  }